// import { storage } from '@/utils';
import request from '@/utils/request';

export function getDicts(ops) {
  if (Array.isArray(ops)) {
    let data = {}
    return new Promise((resolve, reject) => {
      ops.map(item => {
        getData(item).then(res => {
          data[item] = res.data.map(item => ({ name: item.name, code: item.code, disabled: item.available }))
          resolve(data)
        }, fail => reject(fail))
      })
    })
  } else {
    return getData(ops)
  }
}

function getData(params) {
  return request({
    url:'/uam/api/dict/findDictMapByParams',
    method: 'post',
    data: {
      params,
      compId: '0'
    }
  })
}

export function getSys() {
  return request({
    url:'/api/getSysList',
    method: 'post',
    headers: {
      vite: true
    }
  }) 
}

export function getJson(params) {
  return request({
    url:'/api/getJsonData',
    method: 'get',
    params: {
      pageNum: 1,
      pageSize: 10,
      ...params,
    },
    headers: {
      vite: true
    }
  }) 
}

export function saveJson(data) {
  return request({
    url:'/api/saveJsonData',
    method: 'post',
    data,
    headers: {
      vite: true
    }
  }) 
}

export function delJson(data) {
  return request({
    url:'/api/delJsonData',
    method: 'post',
    data,
    headers: {
      vite: true
    }
  }) 
}

export function editJson(data) {
  return request({
    url:'/api/editJsonData',
    method: 'post',
    data,
    headers: {
      vite: true
    }
  }) 
}